using Engine;
using Game;

namespace SCIENEW {
    public class HearthFurnaceOutputPortTransferrer : FluidTransferrer {
        public ComponentHearthFurnace m_componentHearthFurnace;

        public HearthFurnaceOutputPortTransferrer(Point3 position, SubsystemTerrain subsystemTerrain) : base(position, subsystemTerrain) { }

        public void AssignHearthFurnace(ComponentHearthFurnace componentHearthFurnace) {
            m_componentHearthFurnace = componentHearthFurnace;
        }

        public void ResetHearthFurnace() => m_componentHearthFurnace = null;

        public override ITank GetTank() => m_componentHearthFurnace;

        public override int GetFluidValue(ITank tank) => tank.GetTankValue(1);

        public override int RemoveFluid(ITank tank, float volume, out float removedVolume, out int removedTankIndex) {
            if (tank.GetTankVolume(m_componentHearthFurnace.MoltenSteelTankIndex) <= 0) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);
            if (tank is not ComponentHearthFurnace componentHearthFurnace) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);
            //if (!.IsPortOpen) return base.RemoveFluid(tank, volume, out removedVolume, out removedTankIndex);

            int fluidValue = tank.GetTankValue(m_componentHearthFurnace.MoltenSteelTankIndex);
            removedVolume = tank.RemoveTankFluid(m_componentHearthFurnace.MoltenSteelTankIndex, volume);
            removedTankIndex = m_componentHearthFurnace.MoltenSteelTankIndex;
            return fluidValue;
        }
    }
}